package com.hcbd.tdwt.ui.xingyu.fragment;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.core.content.ContextCompat;


import com.hcbd.tdwt.R;
import com.hcbd.tdwt.base.AuthManger;
import com.hcbd.tdwt.base.BaseFragment;


import com.hcbd.tdwt.base.BeidouBoxParams;
import com.hcbd.tdwt.base.bd.BDNotificationManager;
import com.hcbd.tdwt.base.bd.BdToolFactory;
import com.hcbd.tdwt.base.bd.XYSerialPortManage;
import com.hcbd.tdwt.ui.xingyu.activity.PosModeSettingActivity_;
import com.hcbd.tdwt.ui.xingyu.activity.PresetContentActivity_;
import com.hcbd.tdwt.ui.setting.xingyu.activity.AboutActivity_;
import com.hcbd.tdwt.ui.setting.xingyu.activity.AudioSetActivity_;

import com.hcbd.tdwt.ui.setting.xingyu.activity.AuthInfoActivity_;
import com.hcbd.tdwt.ui.setting.xingyu.activity.BdParmSetActivity_;
import com.hcbd.tdwt.ui.setting.xingyu.activity.ChannelSetActivity_;
import com.hcbd.tdwt.ui.setting.xingyu.activity.NotificationSetActivity_;
import com.hcbd.tdwt.ui.setting.xingyu.activity.PositionSetActivity_;
import com.hcbd.tdwt.ui.setting.xingyu.activity.PrivacyAgreeActivity_;
import com.hcbd.tdwt.ui.setting.xingyu.activity.RemoteEscalationSetActivity_;
import com.hcbd.tdwt.ui.setting.xingyu.activity.SendMsgSettingActivity_;
import com.hcbd.tdwt.ui.xingyu.dialog.CustomDialog;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.ViewById;

import java.util.Objects;

/**
 *  create zzh
 *  星宇设置fragment
 */
@SuppressLint("NonConstantResourceId")
@EFragment(R.layout.fragment_my_xingyu)
public class MyFragment extends BaseFragment {
    @ViewById
    RelativeLayout  notifySetRL,audioSetRL,bdParameterRL,presetMessageRL;
    @ViewById
    RelativeLayout  smsSettingsRL,posSettingsRL,channelSetRL,feedbackRL;
    @ViewById
    RelativeLayout  privacyAgreeRL,aboutRL,sendMsgSetRL,authInfoRL,posModeSettingsRL;
    @ViewById
    TextView activationTV;
    @ViewById
    View bdParamBottomView,bdParamTopView,posModeline;
    @AfterViews
    protected void init() {
        if(AuthManger.getAuthManger().isPicOnline()&&AuthManger.getAuthManger().isVoiceOnline()){
            activationTV.setText("已激活");
            activationTV.setTextColor(ContextCompat.getColor(getContext(),R.color.white));
        }else{
            activationTV.setText("未激活");
            activationTV.setTextColor(ContextCompat.getColor(getContext(),R.color.colorPrimary));
        }
        if(BdToolFactory.MOBILE_PHONE_TYPE==BdToolFactory.SATELLITE_MOBILE_PHONE){
            bdParameterRL.setVisibility(View.GONE);
            bdParamBottomView.setVisibility(View.GONE);
            bdParamTopView.setVisibility(View.GONE);
            posModeSettingsRL.setVisibility(View.VISIBLE);
            posModeline.setVisibility(View.VISIBLE);

        }
    }
    //通知设置
    @Click
    void notifySetRL(){
        Intent intent=new Intent();
        intent.setClass(Objects.requireNonNull(this.getActivity()), NotificationSetActivity_.class);
        startActivity(intent);
    }
    //语音设置
    @Click
    void audioSetRL(){
        Intent intent=new Intent();
        intent.setClass(this.getActivity(), AudioSetActivity_.class);
        startActivity(intent);
    }
    @Click
    void presetMessageRL(){
        Intent intent=new Intent();
        intent.setClass(this.getActivity(), PresetContentActivity_.class);
        startActivity(intent);
    }
    @Click
    void bdParameterRL(){
        Intent intent=new Intent();
        intent.setClass(Objects.requireNonNull(this.getActivity()), BdParmSetActivity_.class);
        startActivity(intent);
    }
    @Click
    void channelSetRL(){
        Intent intent=new Intent();
        intent.setClass(Objects.requireNonNull(this.getActivity()), ChannelSetActivity_.class);
        startActivity(intent);
    }
    @Click
    void posSettingsRL(){
        Intent intent=new Intent();
        intent.setClass(Objects.requireNonNull(this.getActivity()), PositionSetActivity_.class);
        startActivity(intent);
    }
    @Click
    void privacyAgreeRL(){
        Intent intent=new Intent();
        intent.setClass(Objects.requireNonNull(this.getActivity()), PrivacyAgreeActivity_.class);
        startActivity(intent);
    }
    @Click
    void aboutRL(){
        Intent intent=new Intent();
        intent.setClass(Objects.requireNonNull(this.getActivity()), AboutActivity_.class);
        startActivity(intent);
    }
    @Click
    void sendMsgSetRL(){
        Intent intent=new Intent();
        intent.setClass(Objects.requireNonNull(this.getActivity()), SendMsgSettingActivity_.class);
        startActivity(intent);
    }
    @Click
    void authInfoRL(){
        Intent intent=new Intent();
        intent.setClass(Objects.requireNonNull(this.getActivity()), AuthInfoActivity_.class);
        startActivity(intent);
    }
    @Click
    void remoteEscalationSetRL(){
        Intent intent=new Intent();
        intent.setClass(Objects.requireNonNull(this.getActivity()), RemoteEscalationSetActivity_.class);
        startActivity(intent);

    }
    @Click
    void posModeSettingsRL(){
//        if(!BeidouBoxParams.isBoxConnectNormal){
//            toast("请打开北斗服务");
//            return;
//        }
        Intent intent=new Intent();
        intent.setClass(Objects.requireNonNull(this.getActivity()), PosModeSettingActivity_.class);
        startActivity(intent);
    }

    /**
     * 终端自毁
     */
//    @Click
//    void terminalDestructSetRL(){
//        if(!BeidouBoxParams.isBoxConnectNormal){
//            toast("请连接终端!");
//            return;
//        }
//        new CustomDialog(this.getActivity(), "是否确认终端自毁？自毁后北斗模块将无法使用。", CustomDialog.DEL_DIALOG, (dialog, content, view) -> {
//            try {
////                BDNotificationManager.getInstance().CCZHS(1);
//                XYSerialPortManage.getInstance().onPackageCCZHS(0);
//                dialog.dismiss();
//            }catch (Exception e){
//                e.printStackTrace();
//            }
//        }).show();
//
//    }


    @Override
    public void onResume() {
        super.onResume();
        if(AuthManger.getAuthManger().isPicOnline()||AuthManger.getAuthManger().isVoiceOnline()){
            activationTV.setText("已激活");
            activationTV.setTextColor(ContextCompat.getColor(getContext(),R.color.white));
        }else{
            activationTV.setText("未激活");
            activationTV.setTextColor(ContextCompat.getColor(getContext(),R.color.colorPrimary));
        }
    }
}
